package com.edushare.common.dao.academics.grades;

import java.util.List;

import com.edushare.common.dao.CayenneBasedDAO;
import com.edushare.common.orm.ORMInterface;
import com.edushare.common.vo.CourseInstances;
import com.edushare.common.vo.GradeKey;
import com.edushare.common.vo.Universities;

public class LetterGradeMap extends CayenneBasedDAO{

	public LetterGradeMap(ORMInterface ormInterface) {
		super(ormInterface);
	}

	public GradeKey getGradeKey(CourseInstances cInst, double marks){
		EntityLetterGrade elg = new EntityLetterGrade(ormInterface);
		List<GradeKey> keyList = elg.getCourseGrades(cInst);
		if(marks < keyList.get(0).getMinimumMarks())
			return keyList.get(0);
		for(int i=0;i<keyList.size();i++){
			if(marks <= keyList.get(i).getMaximumMarks())
				return keyList.get(i);
		}
		return keyList.get(keyList.size()-1);
	}
	
	public GradeKey getGradeKey(String s, CourseInstances cInst){
		EntityLetterGrade elg = new EntityLetterGrade(ormInterface);
		List<GradeKey> keyList = elg.getCourseGrades(cInst);
		for(GradeKey k:keyList){
			if(k.getGradeAlphabet().equals(s))
				return k;
		}
		return null;
	}
	
	public GradeKey getGradeKey(String s, Universities univ){
		UnivLetterGrades ulg = new UnivLetterGrades(ormInterface);
		List<GradeKey> keyList = ulg.getSetOfGrades(univ, ulg.getActiveVersion(univ));
		for(GradeKey k:keyList){
			if(k.getGradeAlphabet().equals(s))
				return k;
		}
		return null;
	}
}
